
function Get-CMSite
{
<#
.Synopsis
    Returns information from SMS_Site WMI Class.
.Description
    Returns all instances of the SMS_Site Class.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMSite
.Example
    Get-CMSite MYTESTLABServer
        Returns all instances of the SMS_Site Class on MYTESTLABServer
.Example
    Get-CMSite MYTESTLABServer get-credential
        Prompts for credentials
.Example
    Get-CMSiet MYTESTLABServer $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Site Class
.Link
    ###http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      Get-CMSite
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/27/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class SMS_Site -ComputerName $ComputerName -Credential $Credential
}#Process

End
{
}#End
}

function Get-CMSiteDefinition
{
<#
.Synopsis
    Returns Site definitions for one ConfigMgr Site.
.Description
    Returns Site Definitions for one ConfigMgr Site.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMSiteDefinition
.Example
    Get-CMSiteDefinition MYTESTLABServer get-credential
        Prompts for credentials
.Example
    Get-CMSiteDefinition MYTESTLABServer $Cred
        uses credentials in $Cred
.Outputs
    Returns all site defininition information for one ConfigMgr Site
.Link
    #http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      Get-CMSiteDefinition
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/27/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($Credential -eq $null)
    {
        
        $oSite = Connect-CMProvider -ComputerName $ComputerName
        $NS = "Root\SMS\Site_" + $oSite.SiteCode
        Invoke-WmiMethod -path SMS_SiteControlFile -name RefreshSCF -argumentList $($oSite.SiteCode) -computername $oSite.Machine -namespace $NS
        get-wmiobject -query "SELECT * FROM SMS_SCI_SiteDefinition WHERE SiteCode = '$($oSite.SiteCode)' AND FileType = 2" -computername $oSite.Machine -namespace $NS
    }
    else 
    {
        $oSite = Connect-CMProvider -Computer $ComputerName -Credential $Credential
        $NS = "Root\SMS\Site_" + $oSite.SiteCode
        Invoke-WmiMethod -path SMS_SiteControlFile -name RefreshSCF -argumentList $($oSite.SiteCode) -computername $oSite.Machine -namespace $NS -credential $cred
        get-wmiobject -query "SELECT * FROM SMS_SCI_SiteDefinition WHERE SiteCode = '$($oSite.SiteCode)' AND FileType = 2" -computername $oSite.Machine -namespace $NS -credential $cred
    }
    
}#Process

End
{
}#End
}

function Get-CMSiteDefinitionProps
{
<#
.Synopsis
    Returns site definition properties for a site.
.Description
    Returns site definition properties for a site.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-Get-CMSiteDefinitionProps
        Returns all site definition properties on the local site server.
.Example
    Get-Get-CMSiteDefinitionProps MYTESTLABServer
        Returns all site definition properties on MYTESTLABServer
Get-CMSiteDefinitionProps
.Example
    Get-CMSiteDefinitionProps MYTESTLABServer get-credential
        Prompts for credentials
.Example
    Get-CMSiteDefinitionProps Get-CMSiteDefinitionProps $Cred
        uses credentials in $Cred
.Outputs
    Returns all site definition properties.
.Link
   # http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      Get-CMSiteDefinitionProps
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/27/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    Get-CMSiteDefinition $ComputerName $Credential | ForEach-Object { $_.Props }
}#Process

End
{
}#End
}



function Get-CMIsR2
{
<#
.Synopsis
    Returns a $True if Site has R2 installed, $False otherwise.
.Description
    Returns a $True if Site has R2 installed, $False otherwise.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMIsR2
        Returns ConfigMgr R2 Installation Status on local server.
.Example
    Get-CMIsR2 MYTESTLABServer
        Returns ConfigMgr R2 Installation Status on MYTESTLABServer
.Example
    Get-CMIsR2 MYTESTLABServer get-credential
        Prompts for credentials
.Example
    Get-CMIsR2 MYTESTLABServer $Cred
        uses credentials in $Cred
.Outputs
    Returns $True if ConfigMgr Site is R2, $False otherwise.
.Link
    ##http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      Get-CMIsR2
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/27/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    
		$result = Get-CMSiteDefinitionProps -ComputerName $ComputerName -Credential $cred | ? {$_.PropertyName -eq "IsR2CapableRTM"}
		if (-not $result) {
			return $false
		} elseif ($result.Value = 31) {
			return $true
		} else {
			return $false
		}
            
}#Process

End
{
}#End
}


function Get-CMDistributionPoint
{
<#
.Synopsis
    Returns all Distribution points for a given site.
.Description
    Returns all Distribution points for a given site.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter SiteCode
    ConfigMgr Site Code for the DP(s)
.Parameter Filter
    Enter Custom Filter    
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMDistributionPoint
.Example
    Get-CMDistributionPoint MYTESTLABServer
        Returns all Distribution Points for MYTESTLABServer and all child sites
.Example
    Get-CMDistributionPoint MYTESTLABServer LAB 
        Returns all distribution points for MYTESTLABServer and all child sites, where the Site code = LAB
.Example
    Get-CMPackage MYTESTLABServer LAB get-credential
        Prompts for credentials
.Example
    Get-CMPackage MYTESTLABServer LAB $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances of Distribution Points for a given site, and all child sites.
.Link
    
.Notes
 NAME:      Get-CMDistributionPoint
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$SiteCode ,

[Parameter(Position=2)]
[String]$Filter ,

[Parameter(Position=3)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class SMS_SystemResourceList -ComputerName $ComputerName -Filter $Filter -Credential $Credential | ? {$_.RoleName -eq "SMS Distribution Point"}
}#Process

End
{
}#End
}